package org.jeecg.modules.demo.mes.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.mes.controller.query.ProductionOnlineReplacementQuery;
import org.jeecg.modules.demo.mes.service.IMesProductionOnlineReplacementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 在线换件控制类
 */
@RestController
@Api(tags = "在线换件")
@Slf4j
@RequestMapping("mes/productionOnlineReplacement")
public class MesProductionOnlineReplacementController {

    @Autowired
    private IMesProductionOnlineReplacementService productionOnlineReplacementService;

    @ApiOperation(value = "获取在线换件集合", notes = "获取在线换件集合")
    @GetMapping("queryProductionOnlineReplacementList")
    public Result queryProductionOnlineReplacementList(ProductionOnlineReplacementQuery query) {
        final List<Map<String,Object>> list = productionOnlineReplacementService.queryProductionOnlineReplacementList(query);
        final Integer total = productionOnlineReplacementService.queryProductionOnlineReplacementCount(query);
        IPage<Map<String,Object>> pageList = new Page<>();
        pageList.setTotal(total);
        pageList.setRecords(list);
        return Result.ok(pageList);
    }

    @ApiOperation(value = "替换物料号", notes = "替换物料号")
    @PostMapping("replaceMaterialBarCode")
    public Result replaceMaterialBarCode(@RequestBody ProductionOnlineReplacementQuery query) {
        productionOnlineReplacementService.replaceMaterialBarCode(query);
        return Result.ok();
    }
}
